package com.linkhub.oms.admin.modules.shop.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import com.linkhub.oms.admin.modules.satoken.session.LhSessionContext;
import com.linkhub.oms.admin.modules.shop.domain.param.*;
import com.linkhub.oms.admin.modules.shop.domain.vo.AddShopVO;
import com.linkhub.oms.admin.modules.shop.domain.vo.AddShopVOV2;
import com.linkhub.oms.admin.modules.shop.domain.vo.ShopVO;
import com.linkhub.oms.admin.modules.shop.service.ShopBizService;
import com.linkhub.oms.common.constant.RoleConstant;
import com.linkhub.oms.common.response.DataResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Description: ShopController
 * @Author: echo
 * @Date: 2024/3/20 11:09
 * @Version: 1.0
 */
@Slf4j
@RestController
@Api(tags = {"商店管理模块"})
@RequestMapping("/shop")
@SaCheckLogin
@SaCheckRole(value = {RoleConstant.CUSTOMER})
public class ShopController {

    @Resource
    private ShopBizService shopBizService;

    @GetMapping("/list")
    @ApiOperation(value = "查询商店列表接口")
    public DataResponse<List<ShopVO>> listShops(@Validated ShopQueryParam shopQueryParam) {
        return DataResponse.success(shopBizService.listShops(shopQueryParam));
    }

    @PostMapping
    @ApiOperation(value = "新增商店-授权接口")
    public DataResponse<AddShopVO> saveShop(@Valid @RequestBody AddShopParam addShopParam) {
        return DataResponse.success(shopBizService.saveShop(addShopParam));
    }

    @PostMapping("/v2")
    @SaIgnore
    @ApiOperation(value = "新增商店-授权接口V2")
    public DataResponse<AddShopVOV2> saveShopV2( @Valid @RequestBody AddShopParamV2 addShopParamV2) {
        return DataResponse.success(shopBizService.saveShopV2(addShopParamV2));
    }

    @PutMapping
    @ApiOperation(value = "编辑商店-授权接口")
    public DataResponse<Void> editShop(@Valid @RequestBody EditShopParam editShopParam) {
        shopBizService.updateShopName(editShopParam);
        return DataResponse.success();
    }

    @PostMapping("/access_token")
    @ApiOperation(value = "通过code获取access_token接口")
    public DataResponse<Void> acquireAccessToken(@Valid @RequestBody AuthorizationGrantParam grantParam) {
        shopBizService.updateShopToken(grantParam);
        return DataResponse.success();
    }

}
